import React, { useState, useCallback } from "react";

export default () => {
  const [count, setCount] = useState(0);
  const [num, setNum] = useState(0);
  let callback = useCallback(() => {
    console.log(count);
    return count;
  }, [num]);
  return (
    <div>
      <h1>useCallback</h1>
      <h2>状态count: {count}</h2>
      <h2>状态num: {num}</h2>
      <h3>
        callback状态:
        {callback()}
      </h3>
      <button
        onClick={(e) => {
          setCount(count + 1);
        }}
      >
        改变count
      </button>
      <button
        onClick={(e) => {
          setNum(num + 1);
        }}
      >
        改变num
      </button>
    </div>
  );
};
